package com.lightjet.macross.base.awf.repository;

import com.lightjet.macross.base.awf.domain.BizAgent;
import com.lightjet.macross.common.core.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : lijia
 * @version : 1.0 2019-04-03 09:05
 * description : 流程代理数据层接口
 */
@Repository("bizAgentRepository")
public interface BizAgentRepository extends BaseRepository<BizAgent,Integer> {

    @Modifying
    @Query("update BizAgent t set t.enable = 0 where current_timestamp not between t.starttime and t.endtime")
    void refreshExpired();

    List<BizAgent> findByPrincipalIdAndEnable(String principalid, byte enable);

    List<BizAgent> findByEnable(byte enable);

    @Modifying
    @Query("update BizAgent t set t.enable = 0 where t.id in :ids")
    void batchExpire(@Param("ids") List<Integer> ids);
}
